<html>
<!-- this file goes through the video and picture folders in the media directory to show the user the content -->
<!-- the following code, will loop through the top directory in the folder, and add every folder in it to a list, it will
	then go through the folder list, and print out every file. And add sub folders back to the list. -->
<head><title>Editing DMF Playlists</title>
<link rel="stylesheet" type="text/css" href="css/Default.css" />
<Script language="javascript" src="data/password.js"></script>
<Script language="javascript" src="exec/login.js"></script>
<noscript>
location.href="noscript.html";
</noscript>
<SCRIPT LANGUAGE="JavaScript">

	window.onload = redir(0);

//name of cookie: 'eomdmf'

</SCRIPT>
</head>
<body style="font-family: arial">
<br>
<center><h1>DMF Editing Playlists</h1></center>
<br>

<center>
<p style="font-family: Arial; font-size:20px;">Press 'Submit' to save any changes made to media playlist.</p><center>
<form method="POST" action="Replace_Media.php"> 
<center>
<b>MOVIES:</b><br>
<textarea name="Playlist_M" id="Playlist_M" rows="10" cols="90" style="color:000000;border: 2px solid black; font-family: Arial">
<?php
//$path = '/earl-tv/media';
$path = 'media';//this is for working wit the earl server. Ensure line above this one is commented out.

//Set strings for directories containing videos + pictures
$dir_v = getcwd().'/media/video/';


//get list of files+folders in those directories
$video =  scandir($dir_v,0);
$dirv;
//go through top folder
for($i = 0; $i < sizeof($video); $i++){

	if(!is_file($dir_v.'/'.$video[$i])){//it's not a file.
		if( strlen($video[$i]) >3){
		//add folder to folder list for further parsing
			$dirv[] = $video[$i];
		}
	}else{
		if( strlen($video[$i]) > 3){
		//show file name on list
			echo $path.'/video/'.$video[$i]."\n";
		}
	}
}

//go through folder list
for($i = 0; $i < sizeof($dirv); $i++){

	$tmp = scandir($dir_v.$dirv[$i]);
	for($j =0; $j <sizeof($tmp); $j++){
	
		if(!is_file($dir_v.$dirv[$i].'/'.$tmp[$j])){//is not a file.
			if( strlen($tmp[$j]) >3){
			//add this folder to end of folder list
				$dirv[] = $dirv[$i].'/'.$tmp[$j];
			}
		}else{
			if( strlen($tmp[$j]) > 3){
			//show file name
				echo $path.'/video/'.$dirv[$i].'/'.$tmp[$j]."\n";
			}
		}
		
	}
}
?>
</textarea>
<br><br><b>Pictures:</b><br>
<textarea name="Playlist_P" id="Playlist_P" rows="10" cols="90" style="color:000000;border: 2px solid black; font-family: Arial">
<?php
//Set strings for directories containing videos + pictures
$dir_p = getcwd().'/media/pictures/';


//get list of files+folders in those directories
$pics =  scandir($dir_p,0);
$dirp;
//go through top folder
for($i = 0; $i < sizeof($pics); $i++){
	if(!is_file($dir_p.'/'.$pics[$i])){
		if( strlen($pics[$i]) >3){
		//add folder to folder list for further parsing
			$dirp[] = $pics[$i];
		}
	}else{
		if( strlen($pics[$i]) > 3){
		//show file name on list
			echo $path.'/pictures/'.$pics[$i]."\n";
		}
	}
}

//go through folder list
for($i = 0; $i < sizeof($dirp); $i++){

	$tmp = scandir($dir_p.$dirp[$i]);
	for($j =0; $j <sizeof($tmp); $j++){
		if(!is_file($dir_p.$dirp[$i].'/'.$tmp[$j])){
			if( strlen($tmp[$j]) >3){
			//add this folder to end of folder list
				$dirp[] = $dirp[$i].'/'.$tmp[$j];
			}
		}else{
			if( strlen($tmp[$j]) > 3){
			//show file name
				echo $path.'/pictures/'.$dirp[$i].'/'.$tmp[$j]."\n";
			}
		}
		
	}
}
?>
</textarea>
<br><br>
</center>
<center><input id="subbut" type="submit" value="Submit Playlist"></center>
</form>
<FORM METHOD="LINK" ACTION="index.html">
<INPUT TYPE="submit" VALUE="Home Page">
</FORM>
<FORM METHOD="LINK" ACTION="LoggedIn.php">
<INPUT TYPE="submit" VALUE="Return to Main Menu">
</FORM>
</center>
</body>
</html>

